<% layout('/layouts/default.html', {title: '海外仓管理', libs: ['validate','fileupload','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(overseasWarehouse.isNewRecord ? '新增海外仓' : '编辑海外仓')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${overseasWarehouse}" action="${ctx}/logistics/overseaswarehouse/overseasWarehouse/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="overseasWarehouseId"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="overseasWarehouseCode" readonly="true" placeholder="自动生成" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('服务订单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="serviceOrderId" items="${listServiceOrder}"
                                itemLabel="serviceOrderCode" itemValue="serviceOrderId" blankOption="true" class="form-control "  readonly="true" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="customerId" items="${listCustomer}"
                                itemLabel="customerName" itemValue="customerId" blankOption="true" class="form-control"  readonly="true" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('外商名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="foreignBusinessmenId" items="${listSupplier}"
                                itemLabel="supplierName" itemValue="supplierId" blankOption="true" class="form-control "  readonly="true"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('国内资方')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="investorId" items="${listSupplier}"
                                itemLabel="supplierName" itemValue="supplierId" blankOption="true" class="form-control " readonly="true" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('供货外商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="supplierId" items="${listSupplier}"
                                itemLabel="supplierName" itemValue="supplierId" blankOption="true"  class="form-control" readonly="true" />
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('物流信息')}</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('收车日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="date" readonly="true" maxlength="20" class="form-control laydate required"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('装箱时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="packingDate" readonly="true" maxlength="20" class="form-control laydate"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('出口手续完结时间')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="finishDate" readonly="true" maxlength="20" class="form-control laydate"
									dataFormat="date" data-type="date" data-format="yyyy-MM-dd"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('海外仓库')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="overseasWarehouse" items="${listWarehouse}" id="warehouseId"
                                itemLabel="warehouseName" itemValue="warehouseId" blankOption="true" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('仓库联系人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="contact" id="contact" maxlength="100" class="form-control required"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('海外仓服务商')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
                                <#form:select path="serviceProvider" id="supplierProvider" items="${listSupplier}"
                                itemLabel="supplierName" itemValue="supplierId" blankOption="true"  class="form-control "  />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('联系电话')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="phone" id="phone" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('送车人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="sender" maxlength="100" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('目的港')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="toPort" dictType="erp_harbor_list" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required ">*</span> ${text('运输方式')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="transportMethod" dictType="erp_transport_type" class="form-control required" />
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('是否出运')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:radio path="shippedFlag" dictType="sys_yes_no" class="form-control required"/>
							</div>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('车辆明细')}</div>
                <div class="ml10 mr10">
                    <table id="overseasWarehouseDetailDataGrid"></table>
                   <!-- <% if (hasPermi('logistics:overseaswarehouse:overseasWarehouse:edit')){ %>
                    <a href="#" id="overseasWarehouseDetailDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
                    <% } %>-->
                </div>
                <div class="form-unit">${text('附件信息')}</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2">
								<span class="required hide">*</span> ${text('附件上传')}：</label>
							<div class="col-sm-10">
								<#form:fileupload id="uploadFile" bizKey="${overseasWarehouse.id}" bizType="overseasWarehouse_file"
									uploadType="all" class="" readonly="false" preview="true"/>
							</div>
						</div>
					</div>
				</div>
                <div class="form-unit">${text('系统信息')}</div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createDate" class="form-control" disabled="true"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('创建人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="createBy" class="form-control" disabled="true"/>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改日期')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateDate" readonly="true" maxlength="20" class="form-control"
                                dataFormat="datetime2" data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group">
                            <label class="control-label col-sm-4" title="">
                                <span class="required hide">*</span> ${text('最后修改人')}：<i class="fa icon-question hide"></i></label>
                            <div class="col-sm-8">
                                <#form:input path="updateBy" readonly="true" maxlength="20" class="form-control"/>
                            </div>
                        </div>
                    </div>
                </div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('logistics:overseaswarehouse:overseasWarehouse:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化海外仓明细DataGrid对象
$("#overseasWarehouseDetailDataGrid").dataGrid({
	data: ${toJson(overseasWarehouse.overseasWarehouseDetailList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'overseasWarehouseDetailId', editable:true, hidden:true},
		{header:'${text("服务订单行号")}', name:'rowNumber', hidden:true, width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'}},
       /* {header:'${text("车辆")}', name:'carId', width:300, editable:true, edittype:'select', editoptions:{'maxlength':'64', 'class':'form-control',
            items: ${toJson(tcarList)},
            itemLabel: 'carName', itemValue: 'carId', dataInit: function(element){
                $(element).select2().on("change",function(){
                    $(this).resetValid();
                });
            }
        }},*/
        {header:'${text("车辆")}', name:'carId', width:100,editable:true, hidden:true},
        {header:'${text("车辆")}', name:'carName', width:300, editable:false, edittype:'text', editoptions:{'maxlength':'64', 'class':'form-control'}},
        {header:'${text("车型")}', name:'model', editable:true, hidden:true},
        {header:'${text("车型")}', name:'model', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("车架号")}', name:'frameNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("车架号")}', name:'frameNumberOld', width:150, editable:true,  hidden:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("发动机号")}', name:'engineNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("车身颜色")}', name:'color', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("生产日期")}', name:'productionDate', width:150, 
			formatter:'date', formatoptions:{srcformat:'Y-m-d',newformat:'Y-m-d'},
			editable:true, edittype:'text', editoptions:{'class':'form-control laydate required', 'readonly':'true',
				dataInit: function(element){
					laydate.render({elem:element, type:'date', format:'yyyy-MM-dd'});
				}
			}
		},
		{header:'${text("原厂地")}', name:'factory', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("轮胎尺寸")}', name:'tireSize', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("座位数")}', name:'seatNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
		{header:'${text("里程数")}', name:'milage', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control required'}},
        {header:'${text("状态")}', name:'warehousestatus', editable:true, hidden:true},
        {header:'${text("状态")}', name:'warehousestatus', width:100,
			editable:false, edittype:'select',formatter: function(val, obj, row, act){
                return js.getDictLabel(${@DictUtils.getDictListJson('erp_logistics_status')}, val, '${text("")}', true);
            }
		},
        {header:'${text("文件上传")}', name:'id', align:"center", width:200,
            editable: true, edittype: "custom", editoptions: {
                custom_element: function(val, editOptions) {
                    return js.template('fileuploadTpl', {
                        id: 'fileupload_'+editOptions.id, title: '区域选择',
                        bizKey: val, bizType: 'overseasWarehouseDetail_file', cssClass: ''
                    });
                }
            }
        },
		{header:'${text("TT付款单号")}', name:'paymentOrderCode', width:150, editable:false, edittype:'text', editoptions:{'maxlength':'100', 'class':'form-control'}},
		{header:'${text("海外仓ID")}', name:'overseasWarehouseId.overseasWarehouseId', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
            if(obj.rowId.length < 10) {
                //actions.push('<a href="#" data-confirm-success="alert(\'我是回调\')"  onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#overseasWarehouseDetailDataGrid\').dataGrid(\'delRowData\',\'' + obj.rowId + '\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
                 actions.push('<a href="#" onclick="deleteRow('+obj.rowId+')"><i class="fa fa-trash-o"></i></a>&nbsp;');
            }
            /* if (val == 'new'){
              }else{
                actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#overseasWarehouseDetailDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
              }*/
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#overseasWarehouseDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {overseasWarehouseDetailId: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'overseasWarehouseDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,warehousestatus,overseasWarehouseDetailId,overseasWarehouseDetail_file,overseasWarehouseDetail_file__del,rowNumber,carId,model,frameNumber,engineNumber,color,productionDate,factory,tireSize,seatNumber,milage,paymentOrderCode,overseasWarehouseId.overseasWarehouseId', // 提交数据列表的属性字段

    frozenCols: true,
	// 加载成功后执行事件
	ajaxSuccess: function(data){

	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>
<script id="fileuploadTpl" type="text/template">//<!--<div>
<#form:fileupload id="{{d.id}}" bizKey="{{d.bizKey}}" bizType="{{d.bizType}}"
	uploadType="all" class="{{d.cssClass}}" isMini="true" preview="true"/>
</div>//--></script>


<script>
	function deleteRow(rowid){
        js.confirm("你确认要删除这条数据吗?", function(){
            $('#overseasWarehouseDetailDataGrid').dataGrid('delRowData', rowid);
            if (typeof window.webuploaderRefresh == 'function') {
                window.webuploaderRefresh();
            }
        });
	}

    $("#warehouseId").change(function () {
        var id = $(this).val();
        var url = "${ctx}/base/warehouse/twarehouse/getOneById?warehouseId="+id;
        $.post(url,null,function (result) {
            js.log(result.twarehouse)
            if (result.twarehouse){
                var warhouse = result.twarehouse;
                $("#contact").val(warhouse.contact);
                $("#supplierProvider").val(warhouse.serviceProvider).trigger('change');
                $("#phone").val(warhouse.phone);
            }
        });
    });
</script>

